from Util.pyh import *
from Util.pyf import PyF
from Util.datatransform import DataT

def htmltest():
      
    page = PyH('My wonderful PyH page')
    page.addCSS('myStylesheet1.css', 'myStylesheet2.css')
    page.addJS('myJavascript1.js', 'myJavascript2.js')
    page << h1('My big title', cl='center')
    page << div(cl='myCSSclass1 myCSSclass2', id='myDiv1') << p('I love PyH!', id='myP1')
    mydiv2 = page << div(id='myDiv2')
    mydiv2 << h2('A smaller title') + p('Followed by a paragraph.')
    page << div(id='myDiv3')
    page.myDiv3.attributes['cl'] = 'myCSSclass3'
    page.myDiv3 << p('Another paragraph')
    page.printOut()
     
def tabletest():
    data_list = PyF('testfile.txt').file_analysis()
    page = PyH('Table Page')
    page << style(PyF("../HTMLFile/css/cssfile.css").read_file())
    page << script(PyF("../HTMLFile/js/jsfile.js").read_file())
#     page.addCSS(os.path.join(os.path.dirname(__file__), "../HTMLFile/css/table.css").replace("\\", "/"))
#     page.addJS((os.path.join(os.path.dirname(__file__), "../HTMLFile/js/doublecolor.js")).replace("\\", "/"))
    file_table = page << table(id='filetable',cl="datalist") 

    for line in data_list:
        if line[0] == 0:
            file_table << tr(td('No.') 
                             + th('Base Line') 
                             + th('Base Code')
                             + th('Type')                             
                             + th('Change Code')
                             + th('Change Line') )
        else:
            file_table << tr(td(line[0])                             
                             + td(DataT(line[1]).data_transform()) 
                             + td(DataT(line[3]).data_transform()) 
                             + td(DataT(line[5]).data_transform())                             
                             + td(DataT(line[4]).data_transform())
                             + td(DataT(line[2]).data_transform()) 
                             )
    page.printOut('/home/allenyang/Desktop/123.html')
    
    
    
if __name__ == "__main__":
    tabletest()
    htmltest()
